import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:ichinesereader/controller/books.dart';
import 'package:ichinesereader/pages/teacher/homeworkStepper.dart';
import 'package:ichinesereader/widgets/dialogs/simpleAlertDialog.dart';

class FloatingActionButtonThemedBooks extends StatelessWidget {
  FloatingActionButtonThemedBooks({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    BooksController _controller = Get.find();
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: <Widget>[
        SizedBox(
          width: 45.0,
          height: 45.0,
          child: FloatingActionButton(
            foregroundColor: Theme.of(context).primaryColorLight,
            backgroundColor: Theme.of(context).primaryColor,
            heroTag: Text('createassignment program books'),
            tooltip: 'Create Homework'.tr,
            onPressed: () {
              if (_controller.selectedThemedBookItems.length > 0) {
                Get.to(() => HomeworkSteps(
                      isNew: true,
                      books: _controller.selectedThemedBookItems,
                    ));
              } else {
                showGeneralDialog(
                    context: context,
                    transitionDuration: Duration(milliseconds: 400),
                    pageBuilder: (bc, ania, anis) {
                      return SimpleAlertDialog(
                          title: 'No Book'.tr,
                          message:
                              'Please select at least one book to ADD!'.tr);
                    });
              }
            },
            child: Obx(() {
              int? num;
              if (_controller.selectedThemedBookItems.length > 0)
                num = _controller.selectedThemedBookItems.length;

              if (num != null && num > 0) {
                return GFBadge(
                  child: Text('+$num'),
                  size: 32,
                );
              } else {
                return Icon(
                  Icons.add,
                  color: Get.isDarkMode
                      ? Get.theme.primaryColorLight
                      : Get.theme.primaryColorLight,
                  size: 24,
                );
              }
            }),
            elevation: 5,
            splashColor: Colors.grey,
          ),
        ),
      ],
    );
  }
}
